<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="success"  size="mini"  @click="handleYes" v-hasPermi="['gzyss:gzyss:remove']">同意</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" size="mini" @click="handleNo" v-hasPermi="['gzyss:gzyss:remove']">打回</el-button>
      </el-col>
      <el-col :span="1.5">

        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['gzyss:gzyss:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="gzyssList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--      <el-table-column label="唯一标识" align="center" prop="id" />-->
      <el-table-column label="验收编号" align="center" prop="ycode" />
      <el-table-column label="单位名称" align="center" prop="dname" />
      <el-table-column label="建账单位" align="center" prop="jname" />
      <el-table-column label="使用单位" align="center" prop="sname" />
      <el-table-column label="责任人" align="center" prop="zpeople" />
      <el-table-column label="设备名称" align="center" prop="ename" />
      <el-table-column label="规格型号" align="center" prop="models" />
      <el-table-column label="资产分类" align="center" prop="codee" />
      <el-table-column label="所在地点" align="center" prop="address" />
      <el-table-column label="出厂日期" align="center" prop="birdate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birdate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产厂家" align="center" prop="manfunture" />
      <el-table-column label="是否有合同" align="center" prop="contract" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="success"
            style="width: 50px"
            @click="handleYes(scope.row)"
            v-hasPermi="['gzyss:gzyss:remove']"
          >同意</el-button>
          <el-button
            size="mini"
            type="warning"
            style="width: 50px"
            @click="handleNo(scope.row)"
            v-hasPermi="['gzyss:gzyss:remove']"
          >打回</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改资产购置验收对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="验收表外键" prop="yswid">
          <el-input v-model="form.yswid" placeholder="请输入验收表外键" />
        </el-form-item>
        <el-form-item label="验收编号" prop="ycode">
          <el-input v-model="form.ycode" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="购置编号" prop="gcode">
          <el-input v-model="form.gcode" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="预算" prop="yld">
          <el-input v-model="form.yld" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="发起人" prop="person">
          <el-input v-model="form.person" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="事项标题" prop="title">
          <el-input v-model="form.title" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="单位名称" prop="dname">
          <el-input v-model="form.dname" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="建账单位" prop="jname">
          <el-input v-model="form.jname" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="使用单位" prop="sname">
          <el-input v-model="form.sname" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="管理部门" prop="department">
          <el-input v-model="form.department" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="责任人" prop="zpeople">
          <el-input v-model="form.zpeople" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="需报销人" prop="baoxiao">
          <el-input v-model="form.baoxiao" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="设备名称" prop="ename">
          <el-input v-model="form.ename" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="规格型号" prop="models">
          <el-input v-model="form.models" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="资产分类" prop="codee">
          <el-input v-model="form.codee" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="资产来源" prop="pmethod">
          <el-input v-model="form.pmethod" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="所在地点" prop="address">
          <el-input v-model="form.address" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="设备技术情况" prop="ecir">
          <el-input v-model="form.ecir" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="已折旧期数" prop="depre">
          <el-input v-model="form.depre" placeholder="请输入已折旧期数" />
        </el-form-item>
        <el-form-item label="剩余折旧期数" prop="rest">
          <el-input v-model="form.rest" placeholder="请输入剩余折旧期数" />
        </el-form-item>
        <el-form-item label="税率" prop="rate">
          <el-input v-model="form.rate" placeholder="请输入税率" />
        </el-form-item>
        <el-form-item label="计量单位" prop="per">
          <el-input v-model="form.per" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="出厂日期" prop="birdate">
          <el-date-picker clearable
                          v-model="form.birdate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择出厂日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="验收日期" prop="enddate">
          <el-date-picker clearable
                          v-model="form.enddate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择验收日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="数量" prop="numberr">
          <el-input v-model="form.numberr" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="单价" prop="price">
          <el-input v-model="form.price" placeholder="请输入单价" />
        </el-form-item>
        <el-form-item label="单价入账原值" prop="ori">
          <el-input v-model="form.ori" placeholder="请输入单价入账原值" />
        </el-form-item>
        <el-form-item label="总入账原值" prop="total">
          <el-input v-model="form.total" placeholder="请输入总入账原值" />
        </el-form-item>
        <el-form-item label="已提折旧" prop="hbprov">
          <el-input v-model="form.hbprov" placeholder="请输入已提折旧" />
        </el-form-item>
        <el-form-item label="生产厂家" prop="manfunture">
          <el-input v-model="form.manfunture" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="供货单位" prop="supply">
          <el-input v-model="form.supply" placeholder="请输入供货单位" />
        </el-form-item>
        <el-form-item label="是否有合同" prop="contract">
          <el-input v-model="form.contract" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="合同编号" prop="concode">
          <el-input v-model="form.concode" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="合同金额" prop="money">
          <el-input v-model="form.money" placeholder="请输入合同金额" />
        </el-form-item>
        <el-form-item label="合同" prop="confile">
          <file-upload v-model="form.confile"/>
        </el-form-item>
        <el-form-item label="合同签订日期" prop="condate">
          <el-date-picker clearable
                          v-model="form.condate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择合同签订日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGzyss,addGzyss, handleNo, handleYes } from "@/api/gzyss/gzyss";

export default {
  name: "Gzyss",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 资产购置验收表格数据
      gzyssList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        jname: null,
        sname: null,
        ename: null,
        codee: null,
        status: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询资产购置验收列表 */
    getList() {
      this.loading = true;
      listGzyss(this.queryParams).then(response => {
        this.gzyssList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        yswid: null,
        ycode: null,
        gcode: null,
        yld: null,
        person: null,
        title: null,
        dname: null,
        jname: null,
        sname: null,
        department: null,
        zpeople: null,
        baoxiao: null,
        ename: null,
        models: null,
        codee: null,
        pmethod: null,
        address: null,
        ecir: null,
        depre: null,
        rest: null,
        rate: null,
        per: null,
        birdate: null,
        enddate: null,
        numberr: null,
        price: null,
        ori: null,
        total: null,
        hbprov: null,
        manfunture: null,
        supply: null,
        contract: null,
        constatus: null,
        concode: null,
        money: null,
        confile: null,
        condate: null,
        status: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleYes(row) {
      const companyIds = row.id || this.ids;
      this.$modal.confirm('是否确认同意公司的预算审批？').then(function() {
        return handleYes(companyIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("审批成功");
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消审批'
        });
      });
    },

    handleNo(row) {
      const companyIds = row.id || this.ids;
      this.$modal.confirm('是否确认打回公司的预算审批？').then(function() {
        return handleNo(companyIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("成功打回");
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消审批'
        });
      });
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateGzyss(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGzyss(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除资产购置验收编号为"' + ids + '"的数据项？').then(function() {
        return delGzyss(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('gzyss/gzyss/export', {
        ...this.queryParams
      }, `gzyss_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
